var payHours = 1;
var amount = 0;
$(function(){
	orderNo = _getUrlParam('orderNo');
	$.ajax({
		url:'/park/road/data/getOrderDetail?orderNo='+orderNo,
		type:'get',
		dataType:'json',
		success:function(res){
			$('#streetName').text(res.data.attr.result[0].streetName);
			$('#carLicense').text(res.data.attr.result[0].carLicense)
			var time = res.data.attr.result[0].startTime;
			startTime = time;
			parkingNo = res.data.attr.result[0].parkingNo;
			$('#startTime').text(time.substring(0,4)+'-'+time.substring(4,6)+'-'+time.substring(6,8)+' '+time.substring(8,10)+':'+time.substring(10,12)+':'+time.substring(12,14));
			$.ajax({
				url:'/park/road/data/getPrice?beginTime='+startTime+'&time=1&parkingNo='+parkingNo+'&orderNo='+orderNo,
				type:'get',
				dataType:'json',
				success:function(res){
					if(parseFloat(res.data)<=0){
						$('#amount').text('0')
					}else{
						$('#amount').text(res.data)
					}
				}
			})
		}
	})
})
function _pay(){
	var _needPay = parseFloat($('#amount').text());
	if(_needPay<=0){
		layer.open({
			content : '您无需支付！',
			skin : 'msg',
			time : 2
		//2秒后自动关闭
		});
	}else{
		 $.ajax({
		url:'/park/road/data/getPayInfo?orderNo='+orderNo+'&orderType=1&amount='+$('#amount').text()+'&month='+payHours,
		type:'get',
		dataType:'json',
		success:function(res){
			if('200'==res.code){
				var htmlStr = "<input name=jsonParams id=jsonParams value="+JSON.stringify(res.data.pay)+" />";
				$('#pay').append(htmlStr); 
				$('#pay').submit();   
			}
		}
	}) 
	}
}
function _getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
var startTime = '';
var parkingNo = ''; 
var orderNo = '';
//加法
function _add(){
	var now = parseFloat($('#hours').text());
	now = 0.5+now;
	$('#hours').text(now);
	payHours = now;
	 _getPrice(); 
}
//减法
function _sub(){
	var now = parseFloat($('#hours').text());
	now = now-0.5;
	if(now<0){
		 layer.open({
		    content:'再减就没了'
		    ,skin: 'msg'
		    ,time: 2 //2秒后自动关闭
		  });
	}else{
		$('#hours').text(now);
		payHours = now;
		 _getPrice();
	}
}
//求价格
function _getPrice(){
	var hh = parseFloat(payHours)+1;
	$.ajax({
		url:'/park/road/data/getPrice?beginTime='+startTime+'&time='+hh+'&parkingNo='+parkingNo+'&orderNo='+orderNo,
		type:'get',
		dataType:'json',
		success:function(res){
			if(parseFloat(res.data)<=0){
				$('#amount').text('0')
			}else{
				$('#amount').text(res.data)
			}
		}
	})
}
